//
//  ZJUnfinishedBooksTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/3.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJUnfinishedBooksTableViewCell.h"
#import "CustomLabel.h"
#import "ZJScheduleView.h"
@interface ZJUnfinishedBooksTableViewCell ()
/** 图片 */
@property (nonatomic, strong) UIImageView *imageview;
/** 题目 */
@property (nonatomic, strong) CustomLabel *titleLabel;
/** 进度 */
@property (nonatomic, strong) ZJScheduleView *scheduleView;
/** 标注 */
@property (nonatomic, strong) UILabel *subLabel;
/** 剩余天数 */
@property (nonatomic, strong) UILabel *residueDay;
/** 分割线 */
@property (nonatomic, strong) UILabel *underline;
@end

@implementation ZJUnfinishedBooksTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.imageview];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.subLabel];
        [self.contentView addSubview:self.scheduleView];
        [self.contentView addSubview:self.residueDay];
        [self.contentView addSubview:self.underline];
        
        self.underline.sd_layout
        .bottomSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(7.5 * [UIScreen zj_screenHScale]);
        
        self.imageview.sd_layout
        .topSpaceToView(self.contentView, 12 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.underline, 12 * [UIScreen zj_screenHScale])
        .widthIs(140 * [UIScreen zj_screenWScale]);
        
        self.subLabel.sd_layout
        .bottomEqualToView(self.imageview)
        .leftSpaceToView(self.imageview, 8.5 * [UIScreen zj_screenWScale])
        .widthIs(140 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont subTitleTextFontSize]]);
        
        self.residueDay.sd_layout
        .bottomEqualToView(self.subLabel)
        .leftSpaceToView(self.subLabel, 0)
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightRatioToView(self.subLabel, 1);
        
        self.scheduleView.sd_layout
        .leftEqualToView(self.subLabel)
        .rightEqualToView(self.residueDay)
        .bottomSpaceToView(self.subLabel, 7 * [UIScreen zj_screenHScale])
        .heightIs(15 * [UIScreen zj_screenHScale]);
        
        self.titleLabel.sd_layout
        .leftEqualToView(self.scheduleView)
        .rightEqualToView(self.scheduleView)
        .topEqualToView(self.imageview)
        .bottomSpaceToView(self.scheduleView, 0);
        
    }
    return self;
}

#pragma mark - Setter
- (void)setModel:(ZJStudySpacialDetailModel *)model{
    _model = model;
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    self.subLabel.text = model.CATEGORY_NAMES.firstObject[@"CATEGORY_NAME"];
    self.residueDay.text = @"";
    self.scheduleView.percentage = model.PLAYPERCENTAGE;
    
    self.titleLabel.text = model.NAME;
    [self.titleLabel setLabelSpace:5 * [UIScreen zj_screenHScale]];
    
    self.titleLabel.sd_layout
    .topEqualToView(self.imageview)
    .leftEqualToView(self.scheduleView)
    .widthIs([UIScreen zj_screenWith] - (24 + 140 + 8.5)  * [UIScreen zj_screenWScale])
    .heightIs([self.titleLabel getSpaceLabelHeightFromSpace:5 * [UIScreen zj_screenHScale]]);
    [self.titleLabel updateLayout];
    
}


#pragma mark - Getters

- (UIImageView *)imageview{
    if (_imageview == nil){
        _imageview = [UIImageView new];
        _imageview.contentMode = UIViewContentModeCenter;
        _imageview.layer.borderColor = [UIColor zj_colorWithHexString:@"ededed"].CGColor;
        _imageview.layer.borderWidth = 1 * [UIScreen zj_screenWScale];
    }
    return _imageview;
}

- (CustomLabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [CustomLabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.textInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}
- (ZJScheduleView *)scheduleView{
    if (_scheduleView == nil){
        _scheduleView = [ZJScheduleView new];
    }
    return _scheduleView;
}

- (UILabel *)subLabel{
    if (_subLabel == nil){
        _subLabel = [UILabel new];
        _subLabel.textColor = [UIColor textGrayColor];
        _subLabel.font = [UIFont subTitleTextFont];
        
    }
    return _subLabel;
}
- (UILabel *)residueDay{
    if (_residueDay == nil){
        _residueDay = [UILabel new];
        _residueDay.textColor = [UIColor textGrayColor];
        _residueDay.font = [UIFont subTitleTextFont];
        _residueDay.textAlignment = NSTextAlignmentRight;
    }
    return _residueDay;
}

- (UILabel *)underline{
    if (_underline == nil){
        _underline = [UILabel new];
        _underline.backgroundColor = [UIColor viewBGGrayColor];
    }
    return _underline;
}

@end
